{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Convert Scanco Volumes to Open Standards\n",
    "\n",
    "This notebook illustrates how to convert Scanco microCT images into open standard file formats while preserving critical image metadata."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Install notebook dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "!{sys.executable} -m pip install itk-ioscanco xarray zarr tqdm requests itkwidgets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from tqdm.notebook import tqdm\n",
    "import os\n",
    "\n",
    "from itkwidgets import view\n",
    "\n",
    "import itk\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "import zarr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Download example data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def download_data(url, filename):\n",
    "    if not os.path.exists(filename):\n",
    "        chunk_size = 32 * 1024\n",
    "        r = requests.get(url, stream=True)\n",
    "        total_size = int(r.headers.get('content-length', 0))\n",
    "        pbar = tqdm(unit=\"B\", unit_scale=True, total=int(total_size))\n",
    "        with open(filename, 'wb') as f:\n",
    "            for chunk in r.iter_content(chunk_size=chunk_size): \n",
    "                if chunk: # filter out keep-alive new chunks\n",
    "                    pbar.update(len(chunk))\n",
    "                    f.write(chunk)\n",
    "                    \n",
    "file_name = 'C0004255.ISQ'\n",
    "file_url = 'https://data.kitware.com/api/v1/file/591e56178d777f16d01e0d20/download'\n",
    "download_data(file_url, file_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read in the Scanco image file, *.ISQ* or *.AIM*."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "imageio = itk.ScancoImageIO.New()\n",
    "image = itk.imread(file_name, imageio=imageio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The type of the image is an `itk.Image`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "<class 'itk.itkImagePython.itkImageSS3'>\n"
     ]
    }
   ],
   "source": [
    "print(isinstance(image, itk.Image))\n",
    "print(type(image))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1e1e184334524c68903caeec8f6ce966",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Viewer(geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<itk.itkImagePython.itkImageSS3; pr…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "view(image)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### View the data with standard Python data types\n",
    "\n",
    "Get the pixel data as a NumPy `ndarray`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       ...,\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]]], dtype=int16)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pixel_data = np.asarray(image)\n",
    "pixel_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get the image metadata as a `dict`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CalibrationData': '45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096',\n",
       " 'CreationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'DataRange': (-2813.0, 32767.0),\n",
       " 'Energy': 45.0,\n",
       " 'Intensity': 0.177,\n",
       " 'MeasurementIndex': 4937,\n",
       " 'ModificationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'MuScaling': 4096.0,\n",
       " 'MuWater': 0.7032999992370605,\n",
       " 'NumberOfProjections': 500,\n",
       " 'NumberOfSamples': 1024,\n",
       " 'PatientIndex': 78,\n",
       " 'PatientName': 'COLE-BPBP',\n",
       " 'ReconstructionAlg': 3,\n",
       " 'ReferenceLine': 0.0,\n",
       " 'RescaleIntercept': -1000.0,\n",
       " 'RescaleSlope': 0.34713582434927287,\n",
       " 'RescaleType': 2,\n",
       " 'RescaleUnits': 'mg HA/ccm',\n",
       " 'SampleTime': 400.0,\n",
       " 'ScanDistance': 36.864000000000004,\n",
       " 'ScannerID': 2135,\n",
       " 'ScannerType': 10,\n",
       " 'Site': 5,\n",
       " 'SliceIncrement': 0.036000000000000004,\n",
       " 'SliceThickness': 0.036000000000000004,\n",
       " 'Version': 'CTDATA-HEADER_V1',\n",
       " 'origin': array([0., 0., 0.]),\n",
       " 'spacing': array([0.036, 0.036, 0.036]),\n",
       " 'direction': array([[1., 0., 0.],\n",
       "        [0., 1., 0.],\n",
       "        [0., 0., 1.]])}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metadata = dict(image)\n",
    "metadata"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MetaImage\n",
    "\n",
    "[MetaImage](https://itk.org/Wiki/ITK/MetaIO/Documentation) is a multi-dimension scientific image file format supported by [Kitware](https://www.kitware.com)-supported open source tools, i.e. [ITK](https://www.itk.org) and [VTK](https://www.vtk.org)-based tools.\n",
    "\n",
    "MetaImage:\n",
    "\n",
    "- Supports 3D images with pixel with types like `signed short`.\n",
    "- Image spatial metadata, i.e. `origin`, `spacing`, and `direction`.\n",
    "- Supports additional key / value metadata."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "itk.imwrite(image, 'image.mha')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CalibrationData': '45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096',\n",
       " 'CreationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'DataRange': '32767 32767',\n",
       " 'Energy': '45',\n",
       " 'ITK_InputFilterName': 'MetaImageIO',\n",
       " 'Intensity': '0.177',\n",
       " 'MeasurementIndex': '4937',\n",
       " 'ModificationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'MuScaling': '4096',\n",
       " 'MuWater': '0.7033',\n",
       " 'NumberOfProjections': '500',\n",
       " 'NumberOfSamples': '1024',\n",
       " 'PatientIndex': '78',\n",
       " 'PatientName': 'COLE-BPBP',\n",
       " 'ReconstructionAlg': '3',\n",
       " 'ReferenceLine': '0',\n",
       " 'RescaleIntercept': '-1000',\n",
       " 'RescaleSlope': '0.347136',\n",
       " 'RescaleType': '2',\n",
       " 'RescaleUnits': 'mg HA/ccm',\n",
       " 'SampleTime': '400',\n",
       " 'ScanDistance': '36.864',\n",
       " 'ScannerID': '2135',\n",
       " 'ScannerType': '10',\n",
       " 'Site': '5',\n",
       " 'SliceIncrement': '0.036',\n",
       " 'SliceThickness': '0.036',\n",
       " 'Version': 'CTDATA-HEADER_V1',\n",
       " 'origin': array([0., 0., 0.]),\n",
       " 'spacing': array([0.036, 0.036, 0.036]),\n",
       " 'direction': array([[1., 0., 0.],\n",
       "        [0., 1., 0.],\n",
       "        [0., 0., 1.]])}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_meta = itk.imread('image.mha')\n",
    "dict(image_meta)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NRRD\n",
    "\n",
    "[NRRD](http://teem.sourceforge.net/nrrd/format.html) is the file format from the teem library, popular with the [3D Slicer](https://www.slicer.org/) community."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "itk.imwrite(image, 'image.nrrd')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CalibrationData': '45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096',\n",
       " 'CreationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'DataRange': '',\n",
       " 'Energy': '',\n",
       " 'ITK_InputFilterName': 'NrrdImageIO',\n",
       " 'Intensity': '',\n",
       " 'MeasurementIndex': '',\n",
       " 'ModificationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'MuScaling': '',\n",
       " 'MuWater': '',\n",
       " 'NRRD_kinds[0]': 'domain',\n",
       " 'NRRD_kinds[1]': 'domain',\n",
       " 'NRRD_kinds[2]': 'domain',\n",
       " 'NRRD_space': 'left-posterior-superior',\n",
       " 'NumberOfProjections': '',\n",
       " 'NumberOfSamples': '',\n",
       " 'PatientIndex': '',\n",
       " 'PatientName': 'COLE-BPBP',\n",
       " 'ReconstructionAlg': '',\n",
       " 'ReferenceLine': '',\n",
       " 'RescaleIntercept': '',\n",
       " 'RescaleSlope': '',\n",
       " 'RescaleType': '',\n",
       " 'RescaleUnits': 'mg HA/ccm',\n",
       " 'SampleTime': '',\n",
       " 'ScanDistance': '',\n",
       " 'ScannerID': '',\n",
       " 'ScannerType': '',\n",
       " 'Site': '',\n",
       " 'SliceIncrement': '',\n",
       " 'SliceThickness': '',\n",
       " 'Version': 'CTDATA-HEADER_V1',\n",
       " 'origin': array([0., 0., 0.]),\n",
       " 'spacing': array([0.036, 0.036, 0.036]),\n",
       " 'direction': array([[1., 0., 0.],\n",
       "        [0., 1., 0.],\n",
       "        [0., 0., 1.]])}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_nrrd = itk.imread('image.nrrd')\n",
    "dict(image_nrrd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Zarr\n",
    "\n",
    "[Zarr](https://zarr.readthedocs.io/en/stable/) is a next generation file format popular in the scientific Python community, but also usable across other programming languages.\n",
    "\n",
    "Zarr has many advantages:\n",
    "\n",
    "- A simple format, supporting multi-dimensional arrays and metadata, with broad adoption across the scientific computing community.\n",
    "- Excellent compression.\n",
    "- Distributed, parallel computing friendly.\n",
    "- Web friendly.\n",
    "\n",
    "[xarray](https://xarray.pydata.org/en/stable/) provides an interface for working with label multi-dimensional arrays, and supports serialization to zarr."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray (z: 51, y: 1024, x: 1024)&gt;\n",
       "array([[[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "...\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]]], dtype=int16)\n",
       "Coordinates:\n",
       "  * x        (x) float64 0.0 0.036 0.072 0.108 0.144 ... 36.72 36.76 36.79 36.83\n",
       "  * y        (y) float64 0.0 0.036 0.072 0.108 0.144 ... 36.72 36.76 36.79 36.83\n",
       "  * z        (z) float64 0.0 0.036 0.072 0.108 0.144 ... 1.692 1.728 1.764 1.8\n",
       "Attributes: (12/28)\n",
       "    direction:            [[1. 0. 0.]\\n [0. 1. 0.]\\n [0. 0. 1.]]\n",
       "    CalibrationData:      45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096\n",
       "    CreationDate:         5-JUN-2015 11:09:18.880\n",
       "    DataRange:            (-2813.0, 32767.0)\n",
       "    Energy:               45.0\n",
       "    Intensity:            0.177\n",
       "    ...                   ...\n",
       "    ScannerID:            2135\n",
       "    ScannerType:          10\n",
       "    Site:                 5\n",
       "    SliceIncrement:       0.036000000000000004\n",
       "    SliceThickness:       0.036000000000000004\n",
       "    Version:              CTDATA-HEADER_V1</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'></div><ul class='xr-dim-list'><li><span class='xr-has-index'>z</span>: 51</li><li><span class='xr-has-index'>y</span>: 1024</li><li><span class='xr-has-index'>x</span>: 1024</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-a5302200-831b-4acf-8f86-6a119c993290' class='xr-array-in' type='checkbox' checked><label for='section-a5302200-831b-4acf-8f86-6a119c993290' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>-1000 -1000 -1000 -1000 -1000 -1000 ... -1000 -1000 -1000 -1000 -1000</span></div><div class='xr-array-data'><pre>array([[[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "...\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]]], dtype=int16)</pre></div></div></li><li class='xr-section-item'><input id='section-e9cfb3fd-1932-42ac-ba8b-fa5bd9f2f4b7' class='xr-section-summary-in' type='checkbox'  checked><label for='section-e9cfb3fd-1932-42ac-ba8b-fa5bd9f2f4b7' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>x</span></div><div class='xr-var-dims'>(x)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0 0.036 0.072 ... 36.79 36.83</div><input id='attrs-77c928f5-e7d0-44bc-bd12-2a50b705b842' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-77c928f5-e7d0-44bc-bd12-2a50b705b842' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1b2cf6c6-01ac-42f2-af98-c531399548ee' class='xr-var-data-in' type='checkbox'><label for='data-1b2cf6c6-01ac-42f2-af98-c531399548ee' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.0000e+00, 3.6000e-02, 7.2000e-02, ..., 3.6756e+01, 3.6792e+01,\n",
       "       3.6828e+01])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>y</span></div><div class='xr-var-dims'>(y)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0 0.036 0.072 ... 36.79 36.83</div><input id='attrs-667a84e2-901d-4e72-9ed2-5ef6c34ea5a0' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-667a84e2-901d-4e72-9ed2-5ef6c34ea5a0' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3df15cea-b5c2-423f-8b08-adc85ee7825d' class='xr-var-data-in' type='checkbox'><label for='data-3df15cea-b5c2-423f-8b08-adc85ee7825d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.0000e+00, 3.6000e-02, 7.2000e-02, ..., 3.6756e+01, 3.6792e+01,\n",
       "       3.6828e+01])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>z</span></div><div class='xr-var-dims'>(z)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0 0.036 0.072 ... 1.728 1.764 1.8</div><input id='attrs-d7085e37-6f53-4289-af9b-733a0bd7d204' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d7085e37-6f53-4289-af9b-733a0bd7d204' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-bee8f554-3f0c-44f1-b95b-0ca2bc3de0a3' class='xr-var-data-in' type='checkbox'><label for='data-bee8f554-3f0c-44f1-b95b-0ca2bc3de0a3' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.   , 0.036, 0.072, 0.108, 0.144, 0.18 , 0.216, 0.252, 0.288, 0.324,\n",
       "       0.36 , 0.396, 0.432, 0.468, 0.504, 0.54 , 0.576, 0.612, 0.648, 0.684,\n",
       "       0.72 , 0.756, 0.792, 0.828, 0.864, 0.9  , 0.936, 0.972, 1.008, 1.044,\n",
       "       1.08 , 1.116, 1.152, 1.188, 1.224, 1.26 , 1.296, 1.332, 1.368, 1.404,\n",
       "       1.44 , 1.476, 1.512, 1.548, 1.584, 1.62 , 1.656, 1.692, 1.728, 1.764,\n",
       "       1.8  ])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-3703144d-7308-4227-b248-69df2d15a041' class='xr-section-summary-in' type='checkbox'  ><label for='section-3703144d-7308-4227-b248-69df2d15a041' class='xr-section-summary' >Attributes: <span>(28)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>direction :</span></dt><dd>[[1. 0. 0.]\n",
       " [0. 1. 0.]\n",
       " [0. 0. 1.]]</dd><dt><span>CalibrationData :</span></dt><dd>45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096</dd><dt><span>CreationDate :</span></dt><dd>5-JUN-2015 11:09:18.880</dd><dt><span>DataRange :</span></dt><dd>(-2813.0, 32767.0)</dd><dt><span>Energy :</span></dt><dd>45.0</dd><dt><span>Intensity :</span></dt><dd>0.177</dd><dt><span>MeasurementIndex :</span></dt><dd>4937</dd><dt><span>ModificationDate :</span></dt><dd>5-JUN-2015 11:09:18.880</dd><dt><span>MuScaling :</span></dt><dd>4096.0</dd><dt><span>MuWater :</span></dt><dd>0.7032999992370605</dd><dt><span>NumberOfProjections :</span></dt><dd>500</dd><dt><span>NumberOfSamples :</span></dt><dd>1024</dd><dt><span>PatientIndex :</span></dt><dd>78</dd><dt><span>PatientName :</span></dt><dd>COLE-BPBP</dd><dt><span>ReconstructionAlg :</span></dt><dd>3</dd><dt><span>ReferenceLine :</span></dt><dd>0.0</dd><dt><span>RescaleIntercept :</span></dt><dd>-1000.0</dd><dt><span>RescaleSlope :</span></dt><dd>0.34713582434927287</dd><dt><span>RescaleType :</span></dt><dd>2</dd><dt><span>RescaleUnits :</span></dt><dd>mg HA/ccm</dd><dt><span>SampleTime :</span></dt><dd>400.0</dd><dt><span>ScanDistance :</span></dt><dd>36.864000000000004</dd><dt><span>ScannerID :</span></dt><dd>2135</dd><dt><span>ScannerType :</span></dt><dd>10</dd><dt><span>Site :</span></dt><dd>5</dd><dt><span>SliceIncrement :</span></dt><dd>0.036000000000000004</dd><dt><span>SliceThickness :</span></dt><dd>0.036000000000000004</dd><dt><span>Version :</span></dt><dd>CTDATA-HEADER_V1</dd></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray (z: 51, y: 1024, x: 1024)>\n",
       "array([[[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "...\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]],\n",
       "\n",
       "       [[-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        ...,\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000],\n",
       "        [-1000, -1000, -1000, ..., -1000, -1000, -1000]]], dtype=int16)\n",
       "Coordinates:\n",
       "  * x        (x) float64 0.0 0.036 0.072 0.108 0.144 ... 36.72 36.76 36.79 36.83\n",
       "  * y        (y) float64 0.0 0.036 0.072 0.108 0.144 ... 36.72 36.76 36.79 36.83\n",
       "  * z        (z) float64 0.0 0.036 0.072 0.108 0.144 ... 1.692 1.728 1.764 1.8\n",
       "Attributes: (12/28)\n",
       "    direction:            [[1. 0. 0.]\\n [0. 1. 0.]\\n [0. 0. 1.]]\n",
       "    CalibrationData:      45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096\n",
       "    CreationDate:         5-JUN-2015 11:09:18.880\n",
       "    DataRange:            (-2813.0, 32767.0)\n",
       "    Energy:               45.0\n",
       "    Intensity:            0.177\n",
       "    ...                   ...\n",
       "    ScannerID:            2135\n",
       "    ScannerType:          10\n",
       "    Site:                 5\n",
       "    SliceIncrement:       0.036000000000000004\n",
       "    SliceThickness:       0.036000000000000004\n",
       "    Version:              CTDATA-HEADER_V1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_da = itk.xarray_from_image(image)\n",
    "image_da"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_ds = image_da.to_dataset(name='image')\n",
    "with zarr.storage.ZipStore('image.zarr.zip', mode='w', compression=0) as store:\n",
    "    image_ds.to_zarr(store, mode='w', compute=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_ds = xr.open_zarr('image.zarr.zip')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CalibrationData': '45 kVp, 0.5mm Al, BH: 1200mg HA/ccm, Scaling 4096',\n",
       " 'CreationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'Energy': 45.0,\n",
       " 'Intensity': 0.1770000010728836,\n",
       " 'MeasurementIndex': 4937,\n",
       " 'ModificationDate': '5-JUN-2015 11:09:18.880',\n",
       " 'MuScaling': 4096.0,\n",
       " 'MuWater': 0.7032999992370605,\n",
       " 'NumberOfProjections': 500,\n",
       " 'NumberOfSamples': 1024,\n",
       " 'PatientIndex': 78,\n",
       " 'PatientName': 'COLE-BPBP',\n",
       " 'ReconstructionAlg': 3,\n",
       " 'ReferenceLine': 0.0,\n",
       " 'RescaleIntercept': -1000.0,\n",
       " 'RescaleSlope': 0.3471358120441437,\n",
       " 'RescaleType': 2,\n",
       " 'RescaleUnits': 'mg HA/ccm',\n",
       " 'SampleTime': 400.0,\n",
       " 'ScanDistance': 36.86399841308594,\n",
       " 'ScannerID': 2135,\n",
       " 'ScannerType': 10,\n",
       " 'Site': 5,\n",
       " 'SliceIncrement': 0.035999998450279236,\n",
       " 'SliceThickness': 0.035999998450279236,\n",
       " 'Version': 'CTDATA-HEADER_V1',\n",
       " 'origin': array([0., 0., 0.]),\n",
       " 'spacing': array([0.036, 0.036, 0.036]),\n",
       " 'direction': array([[1., 0., 0.],\n",
       "        [0., 1., 0.],\n",
       "        [0., 0., 1.]])}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image_zarr = itk.image_from_xarray(image_ds.image)\n",
    "dict(image_zarr)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
